/*
 * @Author: mjjh
 * @LastEditTime: 2023-04-16 17:44:19
 * @FilePath: \chagpt-shuowen\src\api\index.ts
 * @Description:
 */
import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
import { post } from '@/utils/request'
import useRequest from "@/api/useRequest";

export function fetchChatAPI<T = any>(
  prompt: string,
  options?: { conversationId?: string; parentMessageId?: string },
  signal?: GenericAbortSignal,
) {
  return post<T>({
    url: '/chat',
    data: { prompt, options },
    signal,
  })
}

export function fetchChatAPIProcess<T = any>(
  params: {
    prompt: string
      temperature: number,
      presencePenalty: number,
      frequencyPenalty: number,
      modelName: string,
      topP: number,
      templateId?:string,
    options?: { conversationId?: string; parentMessageId?: string }
    signal?: GenericAbortSignal
    onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void },
) {
  const data: Record<string, any> = {
    prompt: params.prompt,
      temperature: params.temperature,
      presencePenalty: params.presencePenalty,
      frequencyPenalty: params.frequencyPenalty,
      modelName: params.modelName,
      topP: params.topP,
      templateId:params.templateId,
    options: params.options,
  }
  return useRequest({
      url: '/chat_message/send',
      data,
      signal: params.signal,
      onDownloadProgress: params.onDownloadProgress,
      method: "post"
  })
  // return post<T>({
  //   url: '/chat_message/send',
  //   data,
  //   signal: params.signal,
  //   onDownloadProgress: params.onDownloadProgress,
  // })
}
